package edu.cuit.svsp.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.cuit.svsp.entity.Complaint;
import edu.cuit.svsp.entity.Review;
import edu.cuit.svsp.mapper.ReviewMapper;
import edu.cuit.svsp.request.ResPage;
import edu.cuit.svsp.service.ReviewService;
import edu.cuit.svsp.vo.ReviewAddVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @className: ReviewServiceImpl
 * @author: pjy
 * @description: 评论服务层实现类
 * @date: 2024/7/6
 */
@Service
public class ReviewServiceImpl implements ReviewService {
    @Resource
    private ReviewMapper reviewMapper;

    @Transactional
    @Override
    public boolean add(ReviewAddVo vo) {
        return reviewMapper.add(vo);
    }

    @Override
    public List<Review> findByVid(Integer vid) {
        return reviewMapper.findByVid(vid);
    }

    @Override
    public boolean delete(Integer id) {
        return reviewMapper.delete(id);
    }

    @Override
    public boolean updateUp(boolean up, Integer id) {
        if(up){
            return reviewMapper.addUp(id);
        }else{
            return reviewMapper.subUp(id);
        }
    }

    @Override
    public ResPage<List<Review>> list(int page, int size) {
        PageHelper.startPage(page, size);
        List<Review> list = reviewMapper.list();
        PageInfo<Review> pageInfo = new PageInfo<>(list);
        ResPage<List<Review>> resPage = new ResPage<>();
        resPage.setData(list);
        resPage.setPage(page);
        resPage.setSize(size);
        resPage.setTotal(pageInfo.getTotal());
        resPage.setPageTotal(pageInfo.getPages());
        return resPage;
    }

    @Override
    public boolean pass(Integer id) {
        return reviewMapper.pass(id);
    }

    @Override
    public boolean out(Integer id) {
        return reviewMapper.out(id);
    }
}
